package com.jcx.ldzj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jcx.ldzj.entity.RoleInfo;
import com.jcx.ldzj.service.IRoleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.api.ApiController;

import javax.validation.Valid;
import java.util.Arrays;
/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author ld
 * @since 2021-11-13
 */
@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/role-info")
@Api(value = "RoleInfoController", tags = "RoleInfoController")
public class RoleInfoController extends ApiController {
        @Autowired
        private IRoleInfoService iRoleInfoService;
       /**
       * 列表
       * @param pageNum
       * @param pageSize
       * @param roleInfo
       * @return
       */
       @GetMapping("/list")
       @ApiOperation(value = "列表", notes = "传入RoleInfo对象")
       public R<IPage<RoleInfo>> list(Integer pageNum, Integer pageSize,RoleInfo roleInfo) {
            QueryWrapper<RoleInfo> queryWrapper=new QueryWrapper<>(roleInfo);
            queryWrapper.groupBy("update_time_");
            IPage<RoleInfo> page = iRoleInfoService.page(new Page<>(pageNum, pageSize), queryWrapper);
            return R.ok(page);
       }
       /**
       *
       * @param id
       * @return
       */
       @GetMapping("/{id}")
       @ApiOperation(value = "详情", notes = "传入id")
       public R<RoleInfo> view(@PathVariable("id") String id) {
          RoleInfo user = iRoleInfoService.getById(id);
          return R.ok(user);
        }

        /**
        * 新增
        * @param roleInfo
        * @return
        */
        @PostMapping
        @ApiOperation(value = "新增", notes = "传入RoleInfo")
        public R add(@Valid @RequestBody RoleInfo roleInfo) {
          return this.success(iRoleInfoService.save(roleInfo));
        }


        /**
        * 修改
        * @param roleInfo
        * @return
        */
        @PutMapping
        @ApiOperation(value = "修改", notes = "传入RoleInfo")
        public R edit(@Valid @RequestBody RoleInfo roleInfo) {
          return this.success(iRoleInfoService.updateById(roleInfo));
        }

        /**
        * 删除
        */
        @DeleteMapping("/{ids}")
        @ApiOperation(value = "删除", notes = "传入ids")
        public R del(@ApiParam(value = "主键集合", required = true) @PathVariable("ids") String[] ids) {
          return this.success(iRoleInfoService.removeByIds(Arrays.asList(ids)));
        }
 }
